package com.frame.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.frame.FrameWebConstant;
import com.frame.FrameWebException;
import com.frame.domain.HostConfig;
import com.mini.core.dao.MiniDao;
import com.mini.core.utils.StrKit;

/**
 * @author sxjun
 * @version 2016-3-11
 */
@Service
public class HostConfigService {
	@Autowired
	private MiniDao miniDao;
	
	/**
	 * 根据id或者name查询uri
	 * @param idorname
	 * @return
	 */
	@Cacheable(value=FrameWebConstant.DOCKER_URI_CACHE_NAME)
	public String getHostUri(String idorname){
		String uri = null;
		if(StrKit.isBlank(idorname))
			throw new FrameWebException("The param of id or name is null");
		HostConfig host = miniDao.find("SELECT * FROM HOSTCONFIG WHERE (ID=? OR NAME=?)", HostConfig.class, idorname, idorname);
		if(host==null)
			throw new FrameWebException("Id or Name is not exist");
		uri = host.getUri();
		return uri;
	}
	
	
	@CacheEvict(value=FrameWebConstant.DOCKER_URI_CACHE_NAME)
	public void delete(String idorname) {  
	}

}
